package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"house/conf"
)

type House struct {
	Id      int     `json:"id"`
	Address string  `json:"address"`
	Name    string  `json:"name"`
	Bh      int     `json:"bh"`
	Sh      int     `json:"sh"`
	Types   string  `json:"types"`
	Price   float64 `json:"price"`
	S       float64 `json:"s"`
	Sum     float64 `json:"sum"`
}

type JsonR struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

var (
	DB  *gorm.DB
	err error
)

func MysqlInit() {
	var Conf = conf.Con
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", Conf.User, Conf.Password, Conf.Host, Conf.Port, Conf.Database)
	DB, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		fmt.Println("连接数据库失败")
		return
	}
	fmt.Println("连接数据库成功")
	DB.AutoMigrate(&House{})
}
